package com.blb.web;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blb.base.BaseServlet;
import com.blb.entity.User;
import com.blb.service.UserService;
import com.blb.utils.UUIDUtils;

/**
 * 添加用户
 * @author Administrator
 *
 */
@WebServlet("/addUser")
public class AddUserServlet extends BaseServlet {

	private static final long serialVersionUID = 1L;
	
	private UserService userService = new UserService();

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		String sex = req.getParameter("sex");
		String city = req.getParameter("city");
		String job = req.getParameter("job");
		String money = req.getParameter("money");
		String headImg = req.getParameter("headImg");
		
		User user = new User();
		user.setId(UUIDUtils.getID());
		user.setUsername(username);
		user.setPassword(password);
		user.setSex(sex);
		user.setCity(city);
		user.setJob(job);
		user.setHeadImg(headImg);
		user.setMoney(Double.valueOf(money));
		
		try {
			userService.addUser(user);
		} catch (SQLException e) {
			e.printStackTrace();
			resp.getWriter().write("添加失败" + e.getMessage());
		}
		
	}
}
